<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加</title>
    <link href="../../layuiadmin/js/adm/css/bootstrap.css" rel="stylesheet">
    <script src="../../layuiadmin/js/adm/js/vue.js"></script>
    <script src="../../layuiadmin/js/adm/js/vue-resource.js"></script>
    <script src="../../layuiadmin/js/adm/js/jquery.min.js"></script>
    <script src="../../layuiadmin/js/adm/js/bootstrap.js"></script>
    <script src="../../layuiadmin/js/adm/js/getUrlParam.js"></script>
    <script src="../../layuiadmin/js/adm/js/date.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui@1.4/lib/theme-default/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui@1.4/lib/index.js"></script>
    <script src="../../layuiadmin/js/adm/js/jquery.cookie.js"></script>
</head>
<body>
<div id="app" class="container-fluid" style="padding: 30px 15%">
    <form action="" method="POST" class="form-horizontal form-inline">
        <div class="row">
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>日志类型：</b></p>
                <select class="form-control" style="width: 100%" v-model="logtable.typeId.typeId" @change="postlogejld(logtable.typeId.typeId)">
                    <option :value="-1">选择日志类型</option>
                    <option v-for="item in logtype"   :value="item.typeId">{{item.logStairName}}</option>
                </select>
            </div>
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>详细类别：</b></p>
                <select class="form-control" style="width: 100%" v-model="logtable.logSecondId.typeId" >
                    <option :value="-1">选择详细类型</option>
                    <option v-for="item in logtypeej"   :value="item.typeId">{{item.logStairName}}</option>
                </select>
            </div>
        </div>
        <div class="row" style="margin-top: 30px">
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>案件</b></p>
                <input type="text" class="form-control"  data-toggle="modal" data-target="#mt" v-model="logtable.caseId.caseId" style="width: 100%">
            </div>
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>客户名称：</b></p>
                <input type="text" class="form-control" disabled v-model="logtable.caseId.clientId.clientName" style="width: 100%">
            </div>
        </div>
        <div class="row" style="margin-top: 30px">
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>开始时间：</b></p>
                <input type="datetime-local" class="form-control"  @change="datetime()" v-model="logtable.startTime" style="width: 100%">
            </div>
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>结束时间：</b></p>
                <input type="datetime-local" class="form-control" @change="datetime()"  v-model="logtable.entTime" style="width: 100%">
            </div>
        </div>

        <div class="row" style="margin-top: 30px">
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>自报时长(时)：</b></p>
                <input type="text" class="form-control" disabled  v-model="logtable.duration" style="width: 100%">
            </div>
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>更新时间：</b></p>
                <input type="date" class="form-control" v-model="logtable.udpatetime" style="width: 100%">
            </div>
        </div>

        <div class="row" style="margin-top: 30px;margin-bottom: 20px">
            <div class="col-md-6">
                <p><b><span style="color: red">*&nbsp;</span>公开状态：</b>
                    <input type="radio" value="N" v-model="logtable.state" name="state">不公开
                    <input type="radio" value="Y" v-model="logtable.state" name="state">公开
                </p>
                <span style="color: red">
                            提示：公开后客户可通过自主查询来查询服务记录
                        </span>
            </div>


        </div>

        <div class="row" style="margin-bottom: 20px">
            <textarea class="form-control" v-model="logtable.description" rows="5px"  cols="120px">

            </textarea>
        </div>
        <input type="button" class="btn btn-success" value="确定" @click="timesj()">

        <!-- ------------------------------------------------------------------------------------------ -->
        <!-- 模态框 -->
        <div class="modal"  id="mt" >
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <span>选择案件</span>
                        <button class="close" data-dismiss="modal">
                            <span>&times;</span>
                        </button>
                    </div>
                    <div class="modal-body" style="height: 500px">
                        <div class="row"  style="padding-left: 20px" >
                            <div class="col-lg-3">
                                <input type="text"  class="form-control" v-model="casetext">
                            </div>
                            <div class="col-lg-3">
                                <select class="form-control" v-model="casequery" >
                                    <option :value="1">案号搜索</option>
                                    <option :value="2">承办律师搜索</option>
                                    <option :value="3">委托人搜索</option>
                                    <option :value="4">对方当事人搜索</option>
                                    <option :value="5">案由搜索</option>
                                    <option :value="6">受理法院搜索</option>
                                </select>
                            </div>


                            <input type="button" class="btn btn-primary" value="搜索"  @click="casequeryc()">
                        </div>

                        <div class="row"  style="padding-left: 20px;margin-top: 30px;" >
                            <table style="width: 97%;border: none;text-align: center" border="1px" >
                                <tr style="height: 50px">
                                    <td><b>选择</b></td>
                                    <td><b>案件号</b></td>
                                    <td><b>委托人</b></td>
                                    <td><b>对方当事人</b></td>
                                    <td><b>承办律师</b></td>
                                    <td><b>收案日期</b></td>
                                </tr>
                                <tr v-for="item in caselsit" style="height: 50px">
                                    <td><input type="radio" id="ca"  name="anjian"  ></td>
                                    <td>{{item.caseId}}</td>
                                    <td>{{item.clientId.clientName}}</td>
                                    <td>{{item.oppositeId.clientName}}</td>
                                    <td>{{item.mainLawyer.empName}}</td>
                                    <td>{{item.closeDate|formatDate}}</td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <input type="button" class="btn btn-primary"  @click="submit()" value="确定" data-dismiss="modal">
                        <input type="button" class="btn btn-primary" value="关闭" data-dismiss="modal">
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>


<script>
    var vm=new Vue({
        el:'#app',
        data:{
            logtable:{
                logId:"",
                userId:{
                    userId:"",
                    userName:""
                },
                typeId:{
                    typeId:"-1",
                    logStairName:""
                },
                logSecondId:{
                    typeId:"-1",
                    logStairName:""
                },
                state:"N",
                caseId:{
                    caseId:"请选择案件",
                    clientId:{
                        clientName:""
                    }
                },
                startTime:"",
                entTime:"",
                duration:"",
                udpatetime:"null",
                uploading:"",
                description:""
            },
            logtype:[

            ],
            logtypeej:[

            ],
            caselsit:[

            ],
            casetext:"",
            casequery:"1"



        },
        created () {
            this.postlog()
            this.postcase()
            this.postcookie()
        },
        methods: {
            open2() {
                this.$message({
                    showClose: true,
                    message: '添加成功',
                    type: 'success'
                });
            },
            open3() {
                this.$message({
                    showClose: true,
                    message: '请选择更新时间',
                    type: 'error'
                });
            },
            open4() {
                this.$message({
                    showClose: true,
                    message: '请选择案件',
                    type: 'error'
                });
            },
            open5() {
                this.$message({
                    showClose: true,
                    message: '日期必须有(时)(分)',
                    type: 'error'
                });
            },
            open6() {
                this.$message({
                    showClose: true,
                    message: '详细类别不能为空',
                    type: 'error'
                });
            },
            open7() {
                this.$message({
                    showClose: true,
                    message: '请选择日志类型',
                    type: 'error'
                });
            },
            open8() {
                this.$message({
                    showClose: true,
                    message: '结束时间不能小于开始时间',
                    type: 'error'
                });
            },

            postcookie(){
                var userId=$.cookie("redisId")
                this.logtable.userId.userId=userId
            },
            datetime(){         //计算日期差值
                if(this.logtable.startTime!=""&&this.logtable.entTime!=""){
                    this.$http.post('http://localhost:8080/log_table/datetime',{"starttime":this.logtable.startTime,"enttime":this.logtable.entTime},{emulateJSON:true}).then(result =>{
                        if(result.body<0){
                            this.open8()
                            this.logtable.duration=result.body;
                        }else{
                            this.logtable.duration=result.body;
                        }

                    })
                }
            },
            casequeryc(){
                console.log("input框="+this.casetext+"下拉框："+this.casequery)
                this.$http.post('http://localhost:8080/log_table/casequery',{"casetext":this.casetext,"casequery":this.casequery},{emulateJSON:true}).then(result =>{
                    var dat=eval("("+result.body+")")
                        this.caselsit=new Array()   //每次重新new一个list集合给定义的list集合
                        for(var i=0;i<dat.length;i++){
                            this.caselsit.push(dat[i])
                        }
                })
            },
            timesj(){
                if(this.logtable.typeId.typeId=='-1'){
                    this.open7()     //日志必须要有类型
                }else if(this.logtable.duration<0){
                    this.open8()    //开始时间不能大于结束时间
                }else if(this.logtable.logSecondId.typeId=='-1'){
                    this.open6()  //详细类型不能为空
                }else if(this.logtable.startTime==""||this.logtable.entTime==""){
                    this.open5() //时间必须要有（）时（）分
                }else if(this.logtable.caseId.caseId=='请选择案件'){
                    this.open4()   //请选择案件
                }else if(this.logtable.udpatetime=="null"){
                    this.open3()   //请选择更新时间
                }
                else{
                    console.log(this.logtable)
                    this.logtable.startTime=this.formatDate2(this.logtable.startTime)
                    this.logtable.entTime=this.formatDate2(this.logtable.entTime)
                    var jsons=JSON.stringify(this.logtable)
                    console.log(this.logtable);
                    this.$http.post('http://localhost:8080/log_table/insert',{"data":jsons},{emulateJSON:true}).then(result =>{
                        if(result.body=="1"){
                            this.open2()
                            location.href="log_table.html"
                        }else{
                            alert("添加失败")
                        }
                    })
                }

            },
            submit(){   //通过选中的案件号给名称复赋值   模态框
                var sv=$("input[name='anjian']")
                for(var i = 0;i<sv.length; i++){
                    if(sv[i].checked==true){
                        var c=$(sv[i]).parent().parent().find("td").eq(1).text();
                        this.logtable.caseId.caseId=c
                    }
                }
                this.$http.post("http://localhost:8080/log_table/submit",{"caseId":this.logtable.caseId.caseId},{emulateJSON:true}).then(result =>{
                    this.logtable.caseId.clientId.clientName=result.body
                })
            },
            postcase(){
                this.$http.post("http://localhost:8080/log_table/caselist",{},{emulateJSON:true}).then(result =>{
                    var dat=eval("("+result.body+")")
                    if(dat!=null&&dat!=""){
                        this.caselsit=new Array()   //每次重新new一个list集合给定义的list集合
                        for(var i=0;i<dat.length;i++){
                            this.caselsit.push(dat[i])
                        }
                    }else{
                        alert("获取失败")
                    }
                })
            },
            postlog(){    //日志类型
                this.$http.post("http://localhost:8080/log_table/postlog",{},{emulateJSON:true}).then(result =>{
                    var dat=eval("("+result.body+")")
                    if(dat!=null&&dat!=""){
                        this.logtype=new Array()   //每次重新new一个list集合给定义的list集合
                        for(var i=0;i<dat.length;i++){
                            this.logtype.push(dat[i])
                        }
                    }else{
                        alert("获取失败")
                    }
                })
            },
            postlogejld(id){    //通过日志类型获取小类型
                this.$http.post('http://localhost:8080/log_table/postlogejld',{"id":id},{emulateJSON:true}).then(result =>{
                    var dat=eval("("+result.body+")")
                    if(dat!=null&&dat!=""){
                        this.logtypeej=new Array()   //每次重新new一个list集合给定义的list集合
                        for(var i=0;i<dat.length;i++){
                            this.logtypeej.push(dat[i])
                        }
                        this.logtable.logSecondId.typeId='-1';
                    }else{
                        alert("获取失败")
                    }
                })
            },
            formatDate2(value){
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? ('0' + MM) : MM;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) : m;
                let s = date.getSeconds();
                s = s < 10 ? ('0' + s) : s;
               // return y + '-' + MM + '-' + d ;
                 return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
            }

        },
        filters: {
            formatDate: function (value) {      //将时间戳修改为时间单位格式
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1;
                MM = MM < 10 ? ('0' + MM) : MM;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) : m;
                let s = date.getSeconds();
                s = s < 10 ? ('0' + s) : s;
                return y + '-' + MM + '-' + d ;
                // return y + '-' + MM + '-' + d + 'T' + h + ':' + m ;
            }
        }

    })
</script>

</body>
</html>